<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Datatype Records</title>
</head>
<body>
<h1>Records</h1>

<c:url var="editImgUrl" value="/resources/img/edit.png" />
<c:url var="deleteImgUrl" value="/resources/img/delete.png" />
<c:url var="addUrl" value="/thesis/main/datatypes/add" />
<table style="border: 1px solid; width: 100%; text-align:center">
	<thead style="background:#d3dce3">
		<tr>
			<th>Data Type ID</th>
			<th>Name of Data Type</th>
			<th>Description</th>
			<th>Class Name</th>
			<th colspan="2"></th>
			<th>Algorithm Name</th>
			<th colspan="3"></th>
		</tr>
	</thead>
	<tbody style="background:#ccc">
	<c:forEach items="${datatypes}" var="datatype">
		<c:url var="editUrl" value="/thesis/main/datatypes/edit?id=${datatype.id}" />
		<c:url var="deleteUrl" value="/thesis/main/datatypes/delete?id=${datatype.id}" />
		
		<c:if test="${!empty datatype.algorithm}">
			<c:forEach items="${datatype.algorithm}" var="algorithm">
			<tr>
				<td><c:out value="${datatype.id}" /></td>
				<td><c:out value="${datatype.dataTypeName}" /></td>
				<td><c:out value="${datatype.dataDescription}" /></td>
				<td><c:out value="${datatype.className}" /></td>
				<td><a href="${editUrl}"><img src="${editImgUrl}"></img></a></td>
				<td><a href="${deleteUrl}"><img src="${deleteImgUrl}"></img></a></td>
				
				<td><c:out value="${algorithm.className}" /></td>
				<c:url var="addCcUrl" value="/thesis/main/algorithms/add?id=${algorithm.id}" />
				<c:url var="editCcUrl" value="/thesis/main/algorithms/edit?id=${algorithm.id}" />
				<c:url var="deleteCcUrl" value="/thesis/main/algorithms/delete?id=${algorithm.id}" />
				<td><a href="${addCcUrl}">+</a></td>
				<td><a href="${editCcUrl}"><img src="${editImgUrl}"></img></a></td>
				<td><a href="${deleteCcUrl}"><img src="${deleteImgUrl}"></img></a></td>
			</tr>
			</c:forEach>
		</c:if>
		
		<c:if test="${empty datatype.algorithm}">
			<tr>
				<td><c:out value="${datatype.id}" /></td>
				<td><c:out value="${datatype.dataTypeName}" /></td>
				<td><c:out value="${datatype.dataDescription}" /></td>
				<td><c:out value="${datatype.className}" /></td>
				<td><a href="${editUrl}"><img src="${editImgUrl}"></img></a></td>
				<td><a href="${deleteUrl}"><img src="${deleteImgUrl}"></img></a></td>
				
				<td>N/A</td>
				<c:url var="addCcUrl" value="/thesis/main/algorithms/add?id=${algorithm.id}" />
				<td><a href="${addCcUrl}">+</a></td>
				<td></td>
				<td></td>
			</tr>
		</c:if>
		
	</c:forEach>
	</tbody>
</table>

<c:if test="${empty datatypes}">
	No records found. 
</c:if>

<p><a href="${addUrl}">Create new record</a></p>

<br>
    	<c:url var="serverUrl" value="/thesis/main/hello.htm" />
    	<td><a href="${serverUrl}">Server Management</a></td>
    	<br>
    	<c:url var="algorithmUrl" value="/thesis/main/algorithms/" />
    	<td><a href="${algorithmUrl}">Algorithm Management</a></td>
    	<br>
    	<c:url var="dataUrl" value="/thesis/main/datatypes/" />
    	<td><a href="${dataUrl}">Data Type Management</a></td>
    	<br>
    	<c:url var="userUrl" value="/thesis/main/persons/" />
    	<td><a href="${userUrl}">User Management</a></td>

</body>
</html>